/**
 *
 */
package com.ssh.web;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;
import com.ssh.model.Constant;
import com.ssh.model.UpdatePasswd;
import com.ssh.ser.comonstaff.IUpdatePasswdService;

/**
 * @author jack
 *
 */
public class UpdatePasswdAction extends ActionSupport {
	/**
	 *
	 */
	private static final long serialVersionUID = 1L;

	private IUpdatePasswdService iUpdatePasswdService;

	private String newPasswd;
	private String oldPasswd;
	private String passwordComfirm;

	/*
	 * (non-Javadoc)
	 *
	 * @see com.opensymphony.xwork2.ActionSupport#execute()
	 */
	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		String staffId = (String) ServletActionContext.getContext()
				.getSession().get("staffId");
		int updateResult = 0;
		System.out.println("newPasswd"+newPasswd);
		System.out.println("oldPasswd"+oldPasswd);
		System.out.println("passwordComfirm"+passwordComfirm);
		if (newPasswd.equals(passwordComfirm)) {
			updateResult = iUpdatePasswdService.updatePasswd(staffId,
					newPasswd, oldPasswd);
			if (updateResult == Constant.OK)
				return "ok";
			if (updateResult == Constant.FAIL)
				return "error";
		}

		return "error";
	}

	/**
	 * @return the iUpdatePasswdService
	 */
	public IUpdatePasswdService getiUpdatePasswdService() {
		return iUpdatePasswdService;
	}

	/**
	 * @return the newPasswd
	 */
	public String getNewPasswd() {
		return newPasswd;
	}

	/**
	 * @return the oldPasswd
	 */
	public String getOldPasswd() {
		return oldPasswd;
	}

	/**
	 * @return the passwordComfirm
	 */
	public String getPasswordComfirm() {
		return passwordComfirm;
	}

	/**
	 * @param iUpdatePasswdService
	 *            the iUpdatePasswdService to set
	 */
	public void setiUpdatePasswdService(
			IUpdatePasswdService iUpdatePasswdService) {
		this.iUpdatePasswdService = iUpdatePasswdService;
	}

	/**
	 * @param newPasswd
	 *            the newPasswd to set
	 */
	public void setNewPasswd(String newPasswd) {
		this.newPasswd = newPasswd;
	}

	/**
	 * @param oldpasswd
	 *            the oldPasswd to set
	 */
	public void setOldpasswd(String oldPasswd) {
		this.oldPasswd = oldPasswd;
	}

	/**
	 * @param oldPasswd
	 *            the oldPasswd to set
	 */
	public void setOldPasswd(String oldPasswd) {
		this.oldPasswd = oldPasswd;
	}

	/**
	 * @param passwordComfirm
	 *            the passwordComfirm to set
	 */
	public void setPasswordComfirm(String passwordComfirm) {
		this.passwordComfirm = passwordComfirm;
	}

}
